#include "trim.h"

namespace tools
{

void ltrim(std::string &str)
{
	for(unsigned int counter = 0; counter < str.length(); counter++)
	{
		if(str[counter] == ' ')
		{
			str = str.substr(1);
			counter--;
		}
		else
		{
			break;
		}
	}
}

void rtrim(std::string &str)
{
	for(unsigned int counter = str.length()-1; counter >=0; counter--)
	{
		if(str[counter] == ' ' || str[counter] == '\r' || str[counter] == '\b' || str[counter] == '\n')
		{
			str = str.substr(0,str.length()-1);;
		}
		else
		{
			break;
		}
	}
}

void trim(std::string &str)
{
    ltrim(str);
    rtrim(str);
}

} // namespace verema
